package com.gong.DesignPattern.builder.builder;

/**
 * @author GongChang
 * @version 1.0
 * @date 2021/6/10 0010 9:17
 */

public class Computer {

    private String cpu;//必选
    private String ram;//必选
    private String usb;
    private String rom;
    private String keyboard;

    public Computer(Builder builder){
        this.cpu = builder.cpu;
        this.ram = builder.ram;
        this.usb = builder.usb;
        this.rom = builder.rom;
        this.keyboard = builder.keyboard;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "cpu='" + cpu + '\'' +
                ", ram='" + ram + '\'' +
                ", usb='" + usb + '\'' +
                ", rom='" + rom + '\'' +
                ", keyboard='" + keyboard + '\'' +
                '}';
    }

    public static class Builder{
        private String cpu;//必选
        private String ram;//必选
        private String usb;
        private String rom;
        private String keyboard;

        public Builder(String cpu,String ram){
            this.cpu = cpu;
            this.ram = ram;
        }

        public Builder setUsb(String usb){
            this.usb = usb;
            return this;
        }

        public Builder setRom(String rom){
            this.rom = rom;
            return this;
        }

        public Builder setKeyboard(String keyboard){
            this.keyboard = keyboard;
            return this;
        }

        public Computer build(){
            return new Computer(this);
        }
    }

}
